package com.source.multithread.countdownlatch;

import java.util.concurrent.CountDownLatch;

/**
 * @Author wengqy
 * @Date 2020/12/23
 */
public class CountDownLatchDemo {
  private static   CountDownLatch  countDownLatch = new CountDownLatch(5);

      static class  BossThread   extends  Thread{
        @Override
        public void run() {
            try {
                // boss 等待
                System.out.println(Thread.currentThread().getName()+"等待所有人到齐后准备开会。。");
                System.out.println("共有"+countDownLatch.getCount()+"个人在会议室。。");
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"所有人都到齐了，开会吧");
        }
    }

    static  class  EmployeeThread   extends  Thread{
        @Override
        public void run() {

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"到达会议室");
            countDownLatch.countDown();
        }
    }
  
  
    public static void main(String[] args) {

        new BossThread().start();
        for (long i = 0 , j = countDownLatch.getCount(); i<j; i++) {
            new EmployeeThread().start();
        }
    }
}

